//
//  ZJSCFooterView.m
//  ShangHaiHuDongApp
//
//  Created by ZJ on 2017/7/17.
//  Copyright © 2017年 刘应平. All rights reserved.
//

#import "ZJSCFooterView.h"

@interface ZJSCFooterView ()
/** 评论输入框 */
@property (nonatomic, strong) UIButton *commentTextButton;
/** 评论按钮 */
@property (nonatomic, strong) UIImageView *commentButton;
/** 分享按钮 */
@property (nonatomic, strong) UIImageView *noteButton;
/** 分割线 */
@property (nonatomic, strong) UILabel *spaceLine;
/** 评论数量 */
@property (nonatomic, strong) UILabel *numberLabel;
@end

@implementation ZJSCFooterView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        
        [self addSubview:self.commentTextButton];
        [self addSubview:self.commentButton];
        [self addSubview:self.noteButton];
        [self addSubview:self.numberLabel];
        [self addSubview:self.spaceLine];
        [self hiddenShareButton];
    }
    return self;
}


-(void)hiddenShareButton{
    self.commentTextButton.frame = CGRectMake(18 * [UIScreen zj_screenWScale], 10, 213 * [UIScreen zj_screenWScale] + ([UIScreen zj_screenWith] - self.commentTextButton.right - 36 * [UIScreen zj_screenWScale]) / 2, 29);
    
    self.commentButton.frame = CGRectMake(self.commentTextButton.right + 18 * [UIScreen zj_screenWScale], 12, ([UIScreen zj_screenWith] - self.commentTextButton.right - 36 * [UIScreen zj_screenWScale]) , 25);
    self.noteButton.hidden = YES;
    
}


#pragma mark - 点击事件

///评论
- (void)action_commentTextButton:(UIButton *)sender{
    if (self.delegate) {
        [self.delegate ZJSCFooterViewDelegate_commentClick];
    }
}

- (void)action_commentButton{
    if (self.delegate) {
        [self.delegate ZJSCFooterViewDelegate_commentClick];
    }
}

///分享
- (void)action_shareButton{
    if (self.delegate) {
        [self.delegate ZJSCFooterViewDelegate_shareClick];
    }
}


#pragma mark - Setter
- (void)setNumber:(NSString *)number{
    _number = number;
    if (!number || [number isEqualToString:@"0"]) {
        self.numberLabel.hidden = YES;
    }else{
        CGSize size = [NSString zj_sizeOfString:number font:self.numberLabel.font width:[UIScreen zj_screenWith]];
        self.numberLabel.text = number;
        self.numberLabel.frame = CGRectMake(0, 0, size.width + 2 * [UIScreen zj_screenWScale], size.height +  2 * [UIScreen zj_screenWScale]);
        self.numberLabel.centerY = self.commentButton.y;
        self.numberLabel.x = self.commentButton.centerX;
        self.numberLabel.layer.masksToBounds = YES;
        self.numberLabel.layer.cornerRadius =  3 * [UIScreen zj_screenWScale];
    }
}

-(void)setIsActivityIn:(BOOL)isActivityIn
{
    _isActivityIn = isActivityIn;
    NSString * commentString = @"";
    if (isActivityIn) {
        commentString = @"点击讨论";
    }
    else{
        commentString = @"点击评论";
    }
    [self.commentTextButton setTitle:commentString forState:UIControlStateNormal];
    
}

#pragma mark - Getters
- (UIButton *)commentTextButton{
    if (_commentTextButton == nil){
        _commentTextButton = [[UIButton alloc]initWithFrame:CGRectMake(18 * [UIScreen zj_screenWScale], 10, 213 * [UIScreen zj_screenWScale], 29)];
        _commentTextButton.backgroundColor = [UIColor zj_colorWithHexString:@"f3f3f3"];
        _commentTextButton.layer.cornerRadius = 8 ;
        _commentTextButton.titleLabel.font = [UIFont systemFontOfSize:14 * [UIScreen zj_textFontScale]];
        [_commentTextButton setTitle:@"" forState:UIControlStateNormal];
        [_commentTextButton setTitleColor:[UIColor zj_colorWithHexString:@"777777"] forState:UIControlStateNormal];
        [_commentTextButton addTarget:self action:@selector(action_commentTextButton:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _commentTextButton;
}

- (UIImageView *)commentButton{
    if (_commentButton == nil){
        _commentButton = [[UIImageView alloc]initWithFrame:CGRectMake(self.commentTextButton.right + 18 * [UIScreen zj_screenWScale], 12, ([UIScreen zj_screenWith] - self.commentTextButton.right - 36 * [UIScreen zj_screenWScale]) / 2, 25)];
        _commentButton.image = [UIImage imageNamed:@"learn_question_com"];
        _commentButton.userInteractionEnabled = YES;
        _commentButton.contentMode = UIViewContentModeScaleAspectFit;
        UITapGestureRecognizer *tapGester = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(action_commentButton)];
        
        [_commentButton addGestureRecognizer:tapGester];
    }
    return _commentButton;
}

- (UIImageView *)noteButton{
    if (_noteButton == nil){
        _noteButton = [[UIImageView alloc]initWithFrame:CGRectMake(self.commentButton.right, self.commentButton.y, self.commentButton.width, self.commentButton.height)];
        _noteButton.userInteractionEnabled = YES;
        _noteButton.image = [UIImage imageNamed:@"tab_share"];
        _noteButton.contentMode = UIViewContentModeScaleAspectFit;
        UITapGestureRecognizer *tapGester = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(action_shareButton)];
        
        [_noteButton addGestureRecognizer:tapGester];
    }
    return _noteButton;
}

- (UILabel *)numberLabel{
    if (_numberLabel == nil){
        _numberLabel = [UILabel new];
        _numberLabel.backgroundColor = [UIColor themeColor];
        _numberLabel.textColor = [UIColor whiteColor];
        _numberLabel.font = [UIFont systemFontOfSize:12 * [UIScreen zj_textFontScale]];
        _numberLabel.textAlignment = NSTextAlignmentCenter;
    }
    return _numberLabel;
}

- (UILabel *)spaceLine{
    if (_spaceLine == nil){
        _spaceLine = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, self.width, 0.5)];
        _spaceLine.backgroundColor = [UIColor zj_colorWithHexString:@"dedede"];
    }
    return _spaceLine;
}
@end
